package vn.com.epi.re.tools;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import vn.com.epi.re.ApplicationContext;

public class LineNumberReaderHdfs {

    @SuppressWarnings("unused")
    public static int get(String filePath) throws IOException {
        FileSystem fs = ApplicationContext.get().getFileSystem();        
        Path path = new Path(filePath);
        BufferedReader br = null;
        int count = 0;
        try {
            br = new BufferedReader(new InputStreamReader(fs.open(path)));
            String line;
            while ((line = br.readLine()) != null) {
                count++;
            }
            return count;
        } finally {
            if (br != null)
                try {
                    br.close();
                } catch (Exception e) {
                }
        }        
    }
}
